import { postCheckEmail,postResetEmail } from './services';
import { getUserInformation } from '../services';

export default {
  namespace: 'editEmail',
  effects: {
    *setCheckEmail({ payload }, { call, put }) {
      const response = yield call(postCheckEmail, payload);
      const { code, msg } = response;
      if (code === 1) {
        return Promise.resolve(msg);
      }
      return Promise.reject(msg);
    },
    *setResetEmail({ payload }, { call, put }) {
      const response = yield call(postResetEmail, payload);
      const { code, msg } = response;
      if (code === 1) {
        return Promise.resolve(msg);
      }
      return Promise.reject(msg);
    },
    *queryUserInformation({ payload }, { call, put }) {
      const response = yield call(getUserInformation);
      console.log(response);
      const { code, data } = response;
      if (code === 1) {
        yield put({
          type: 'updateUserInformation',
          payload: data,
        });
      }
    },
  },
  reducers: {
    updateUserInformation(state, { payload }) {
      state.information = payload;
      return state;
    },
  },
};
